package com.poul.acfun.ac_utils;

import android.support.annotation.Nullable;

import org.greenrobot.greendao.annotation.NotNull;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

/**
 * Created by poul on 2016/10/19.
 */

public class DateUtil {
    private static final long ONE_SECOND = 1000;
    private static final long ONE_MINITE = ONE_SECOND * 60;
    private static final long ONE_HOUR = ONE_MINITE * 60;
    private static final long ONE_DAY = ONE_HOUR * 24;

    public static String getOtherDateString(@Nullable Date date, int num, SimpleDateFormat format) {
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            calendar.setTime(date);
        }
        calendar.roll(Calendar.DAY_OF_YEAR,num);
        return format.format(calendar.getTime());
    }

    public static String getDateWhitMillis(long timeInMillis){
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeInMillis);
        Date date = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm", Locale.CHINA);
        return format.format(date);
    }

    private static boolean isExpried(Date date){
        Date curDate = new Date();
        long splitTime = curDate.getTime() - date.getTime();
        return splitTime > 2 * ONE_HOUR;
    }

    public static boolean isExpried(Long time){
        return isExpried(new Date(time));
    }
}
